Ext.define('Security.controller.CoreController',
{
    extend : 'Ext.app.Controller',

    stores : [],

    views :
    [
        'login.LoginPage'
    ],

    init : function()
    {

        this.control(
        {
            'loginpage #login' :
            {
                click : function(btn)
                {
                    var values = btn.up('form').getForm().getValues();

                    UserManager.login(values.username, values.password, function(redirectURL, sessionId)
                    {
                        SessionManager.getCurrentUser(function(userName)
                        {
                            if (userName != null)
                            {
                                SessionManager.createUserCookie(userName, sessionId, function()
                                {
                                    var url = SessionManager.getRedirectURL();
                                    if (url == null)
                                    {
                                        url = '/';
                                    }
                                    window.location = url;
                                });
                            }
                        });
                    });
                }
            }
        });
    }
});